package CutLoad.transitions.cloud
{
	import CutLoad.Base;
	import CutLoad.cookies.Fun;
	import CutLoad.cookies.RegPointOperation;
	import CutLoad.transitions.Easing;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;

	/**
	 * 给一个base对象加了鼠标放上去缓动放大，离开缓动缩小 
	 * @author feifei
	 * 
	 */	
	public class EasingMouseOverOut extends Base
	{
		private var target:DisplayObject;
		private var easing:Easing;
		private var numStates:Number=0;
		private var maxScale:Number,offsetOver:Number,offsetOut:Number;
		//
		private var RPO:RegPointOperation;
		/**
		 * 初始化 
		 * @param target 要操作的目标
		 * @param maxScale
		 * @param offset
		 * 
		 */		
		public function EasingMouseOverOut(target:DisplayObject,maxScale:Number=1.5,offsetOver:Number=0.4,offsetOut:Number=0.6)
		{
			if(target.parent==null) throw new Error("操作的目标的parent!=null  ");
			this.target=target;
			this.addEventListener(Event.ENTER_FRAME,enter_frame);
			target.addEventListener(MouseEvent.MOUSE_OVER,over);
			target.addEventListener(MouseEvent.MOUSE_OUT,out);
			this.maxScale=maxScale;
			this.offsetOver=offsetOver;
			this.offsetOut=offsetOut;
			//
			RPO=new RegPointOperation(this.target,new Point(this.target.width/2,this.target.height/2));
		}
		private function enter_frame(e:Event):void{
			if(numStates==0) return;
			var numMax:Number=maxScale
			var sd:Number;
			if(numStates==1){
				if(target.scaleX>=numMax){
					//target.scaleX=numMax;
					//target.scaleY=numMax;
					RPO.setScaleXY(numMax,numMax);
					numStates=0;
					return;
				}
				sd=(numMax-target.scaleX)*offsetOver
			}else if(numStates==2){
				if(target.scaleX<=1){
					//target.scaleX=1;
					//target.scaleY=1;
					RPO.setScaleXY(1,1);
					numStates=0;
					return;
				}
				sd=(1-target.scaleX)*this.offsetOut
			}
			//target.scaleX+=sd;
			//target.scaleY+=sd;
			RPO.addScaleXY(sd,sd);
		}
		override public function killMe():void{
			this.removeEventListener(Event.ENTER_FRAME,enter_frame);
			super.killMe();
		}
		private function over(e:MouseEvent):void{
			numStates=1;
			Fun.setTopDepath(this.target);
		}
		private function out(e:MouseEvent):void{
			numStates=2;
		}
			
	}
}